<?php

namespace Biz\model\TodayNiceGoods;

use Hhz\Mysql\BaseDbModel;
class TodayNiceGoodsModel extends BaseDbModel
{
    public const _CONFIG_FILE_ = 'db_store';

    public const _CONFIG_SELECT_ = 'db_brand_activity';

    public const _DATABASE_ = 'brand_activity';

    public const _TABLE_NAME = 'today_nice_goods';

    //活动类型1:平台配置 2：商业活动
    public const TYPE_BUSY = 2;
    public const TYPE_NORMAL = 1;
    public const TYPE_ARR = [
        self::TYPE_BUSY => "商业活动",
        self::TYPE_NORMAL => "平台配置",
    ];

    //活动状态 1:默认 正常 9：删除
    public const STATUS_NORMAL = 1;
    public const STATUS_DELETE = 9;

    //活动虚拟状态 11：待开始 12：活动中 13：已结束
    public const STATUS_WAIT = 11;
    public const STATUS_ACTING = 12;
    public const STATUS_END = 13;

    //虚拟状态对应值
    public const STATUS_ARR = [
        self::STATUS_WAIT => "待开始",
        self::STATUS_ACTING => "活动中",
        self::STATUS_END => "已结束",
        self::STATUS_DELETE => "删除",
    ];


    /**
     * 获取一行
     * @param $where
     * @param string $field
     * @return array|mixed|null
     */
    public static function first($where, $field = '*')
    {
        $rs = self::get($field, $where);
        if (!$rs) {
            return null;
        }
        return $rs;
    }

    /**
     * 批量查询
     * @param $where
     * @param  $field
     * @return array
     */
    public static function all($where, $field = '*'): array
    {
        return self::select($field, $where) ?: [];
    }

    /**
     * 获取一列的值
     * @param $where
     * @param array $field
     * @return array
     */
    public static function pluck($where, array $field = ['id']): array
    {
        return self::select($field, $where) ?? [];
    }

    /**
     * 从记录中获取单个值
     * @param $where
     * @param string $columns
     * @return array|bool
     */
    public static function value($where, string $columns = 'id')
    {
        return self::get($columns, $where);
    }


}
